// 可选操作符 ?.
// 作用是当对象的属性不存在时,会短路,直接返回undefined 
// 如果存在就会继续执行
type Person = {
    name: string,
    friend?: {
        name: string,
        age?: number,
        girlFriend?: {
            name: string
        }
    }
}

const info: Person = {
    name: "why",
    friend: {
        name: "kobe",
        girlFriend: {
            name: "lily"
        }
    }
}

console.log(info.friend?.name)  //kobe
console.log(info.friend?.age)   //undefined
console.log(info.friend?.girlFriend?.name)  //lily


// ??和！！的作用
//!!将一个其他类型转换为boolean类型
//类似于Boolean(变量)的方式

const message1 = ""
let flag1 = Boolean(message1)   //false
let flag2 = !!message1  //false
console.log(flag1===flag2); //true


// ??是一个逻辑操作符,当操作符的左侧是null或undefined返回右侧操作数,否则返回左侧操作数
const message = "321"
const result = message ?? "123"
console.log(result);

export { }